﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.Framework.Common.Validation;

namespace PSE.Framework.Service.Validation.BusinessRules
{
    public class BaseBusinessRuleValidation<T> where T: new()
    {
        #region [[ Construtor ]]

        public BaseBusinessRuleValidation()
        {
            this.ErrorsList = new List<ValidationError>();
        }

        public BaseBusinessRuleValidation(T entityToValidate)
        {
            this.EntityToValidate = entityToValidate;
            this.ErrorsList = new List<ValidationError>();
        }

        #endregion

        #region [[ Atributos ]]

        public T EntityToValidate { get; set; }
        public List<ValidationError> ErrorsList { get; set; }

        #endregion

        #region [[ Metodos ]]

        /// <summary>
        /// Adiciona um erro a lista
        /// </summary>
        /// <param name="errorNumber">Numero do erro</param>
        public void AddValidationError(int errorNumber) 
        {
            this.ErrorsList.Add(new ValidationError(errorNumber));
        }    

        /// <summary>
        /// Adiciona um erro a lista
        /// </summary>
        /// <param name="errorNumber">Numero do erro</param>
        /// <param name="errorMessage">Mensagem</param>
        public void AddValidationError(int errorNumber, string errorMessage)
        {
            this.ErrorsList.Add(new ValidationError(errorNumber, errorMessage));
        }

        /// <summary>
        /// Adiciona uma lista de erros a lista atual
        /// </summary>
        /// <param name="errors"></param>
        public void AddValidationError(List<ValidationError> errors) 
        {
            this.ErrorsList.AddRange(errors);
        }

        #endregion
    }
}
